package com.freshcity.utils
{
	import com.freshcity.core.GlobalVar;
	import com.freshcity.icons.SexBigIcon;
	import com.greensock.TweenLite;
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.ImageLoader;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;

	public class BitmapUtil
	{
		public static function loadImage(url:String, parent:DisplayObjectContainer):void
		{
			var onImageLoad:Function=function(event:LoaderEvent):void
			{
				TweenLite.from(event.target.content, 0.2, {alpha: 0});
			};
			//create an ImageLoader:
			var imageLoader:ImageLoader=new ImageLoader(url, {name: "photo1", container: parent, x: 0, y: 0, width: 110, height: 135, scaleMode: "proportionalInside", centerRegistration: false, onComplete: onImageLoad});
			//begin loading
			imageLoader.load();
		}

		public static function showAvatarPic(user:*, render:SexBigIcon, isIgnore:Boolean=false):void
		{
			var p:DisplayObject = render.getChildByName("photo1");
			if(p)render.removeChild(p);
			
			if (GlobalVar.LOGIN_USER.level > 3)
			{
				BitmapUtil.loadImage(GlobalVar.MAIN_PATH +"/photo/" + user.id + ".jpg", render);
				return;
			}

			if (user.level && user.level > 3)
			{
				render.lockIcon.visible=true;
			}
			else
			{
				render.lockIcon.visible=false;
			}
		}
	}
}